$.fn.extend({
	slider:function(opt){
		// isDot  Boolean 小圆点是否存在
		opt.isDot = (opt.isDot === undefined) ? true : opt.isDot
		// dotClickable  Boolean 小圆点是否点击
		opt.dotClickable = (opt.dotClickable === undefined) ? true : opt.dotClickable
		// dotBackgroundColor  String  小圆点未聚焦状态的背景色
		opt.dotBackgroundColor = opt.dotBackgroundColor || "#ffffff";
		// dotCurBackgroundColor  String  小圆点聚焦状态的背景色
		opt.dotCurBackgroundColor = opt.dotCurBackgroundColor || "#ff9999";
		// overclickable true 超出边距点击是否有效
		opt.overclickable = (opt.overclickable === undefined) ? true : opt.overclickable
		// method String "slide"(滑动) || "fade"(渐显)   切换方式
		opt.method = opt.method || "fade"
		// autoPlay Boolean 是否自动播放
		opt.autoPlay = opt.autoPlay || false
		// autoTime Number 自动播放间隔(ms)
		opt.autoTime = opt.autoTime || 3000
		// keyboard Boolean 是否允许键盘光标键操控 默认true
		opt.keyboard = (opt.keyboard === undefined) ? true : opt.keyboard




		function changeImg(){
			if(opt.method == "fade"){
				liList.hide().eq(n).fadeIn();
			}
			if(opt.method == "slide"){
				wrap.find("ul").eq(0).animate({
					marginLeft:-(n * wrap.width())
				})
			}
			dotList.css({backgroundColor:opt.dotBackgroundColor}).eq(n).css({backgroundColor:opt.dotCurBackgroundColor})
		}

		var wrap = this;
		var liList = this.find("li");
		var prev = this.find(".adv-prev");
		var next = this.find(".adv-next");
		var count = liList.length;

		// 初始化样式
		if(opt.method == "fade"){
			liList.hide();
			liList.eq(0).show();
		}
		if(opt.method == "slide"){
			this.find("ul").eq(0).css({
				width:this.width() * count
			})
			liList.css({float:"left"})
			this.css({overflow:"hidden"})
		}




		if(opt.isDot){
			// 生成小圆点
			var dotWrap = $("<div class='dotWrap'></div>");
			dotWrap.css({
				position:"absolute",
				bottom:15,
				left:"45%"
			})

			for(var i = 0; i < count;i++){
				dotWrap.appendTo(this)
				var dot = $("<span></span>");
				dot.css({
					width:10,
					height:10,
					borderRadius:"50%",
					backgroundColor:opt.dotBackgroundColor,
					marginRight:10,
					display:"block",
					float:"left"
				})
				dot.appendTo(dotWrap);
			}

			var dotList = this.find(".dotWrap span");
			dotList.eq(0).css({backgroundColor:opt.dotCurBackgroundColor})

			// 赋予小圆点事件
			if(opt.dotClickable){
				dotList.click(function(){
					n = $(this).index();
					changeImg()
				})

				dotList.css({cursor:"pointer"})
			}
		}

		// 当前所在的张数
		var n = 0;

		prev.click(function(){
			if(n > 0){
				--n;
			}
			else{
				if(opt.overclickable){
					n = count - 1;
				}
				else{
					return;
				}
			}
			changeImg()
		})
		next.click(function(){
			if(n < count - 1){
				++n
			}
			else{
				if(opt.overclickable){
					n = 0;
				}
				else{
					return;
				}
			}
			changeImg()
		})

		if(opt.autoPlay){
			var t = setInterval(function(){
				next.click()
			},opt.autoTime)
			this.mouseenter(function(){
				clearInterval(t)
			}).mouseleave(function(){
				t = setInterval(function(){
					next.click()
				},opt.autoTime)
			})
		}

		if(opt.keyboard){
			$(window).keyup(function(e){
				if(e.keyCode == 37){
					prev.click()
				}
				if(e.keyCode == 39){
					next.click();
				}
			})
		}

	}
})